package org.example.aop.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

// 通知类
@Component
@Aspect
public class FirstAdvice {
    @Pointcut("execution(* org.example.aop.target.*.*(..))")
    public void execut() {
    }
    @AfterReturning("execut()")
    public void afterReturning() {
        System.out.println("提交了");
    }
    @Before("execut()")
    public void before() {
        System.out.println("我在你执行之前执行了");
    }
    @Around("execut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("我是环绕之前...");
        //执行目标对象的方法
        Object result = pjp.proceed();
        System.out.println("我是环绕之后...");
        return result;
    }
    @After("execut()")
    public void after() {
        System.out.println("我是最终的通知！");
    }
    @AfterThrowing("execut()")
    public void exception() {
        System.out.println("你的代码出现异常");
    }
}
